function Event () {
  this.obj = {}
  Event.prototype.on = function (type,listen) {
    if (!this.obj[type]) {
      this.obj[type] = []
      this.obj[type].push(listen)
    } else {
      console.log(typeof this.obj[type])
      this.obj[type].push(listen)
    }
  }
  Event.prototype.emit = function (type, ...rest) {
    this.obj[type].forEach(item => {
      item(...rest)
  })
  }
  Event.prototype.once = function (type, listen) {
    var self = this
    function onceDone (...rest) {
      listen(...rest)
      self.removeListen(type, onceDone)
    }
    this.on(type, onceDone)
  }
  Event.prototype.removeListen = function (type, listen) {
    if (!this.obj[type]) {
      console.error(`无${type}监听事件`)
    } else {
      this.obj[type] = this.obj[type].filter(l => l !== listen)
    }
  }
}
module.exports = Event